<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 1] 1.4 Running a Java Application</TITLE>
<META NAME="author" CONTENT="Mark Grand">
<META NAME="date" CONTENT="Thu Jul 31 13:05:19 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="java">
<META NAME="title" CONTENT="Java Language Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Language Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 1<br>Introduction</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch01_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JLR2-CH-1-SECT-4">1.4 Running a Java Application</A></h2>

<P CLASS=para>
To run a Java application, you invoke the Java interpreter,
<I CLASS=emphasis>java</I>, with one or more arguments. The first
argument is always the name of a Java class. Here is how
to run the "Hello World" application:

<DIV CLASS=screen>
<P>
<PRE>
C:\&gt; java HelloWorld
</PRE>
</DIV>

<P CLASS=para>
The capitalization of the class name must match the name used
in the class declaration in the source file. The interpreter loads
the specified class and then calls its <tt CLASS=literal>main()</tt>
method.

<P CLASS=para>
A class can belong to a particular package. This allows the
class to prevent classes in other packages from accessing its declared
variables and methods. If a class is not specified as part of a
package, it automatically becomes part of the default package. Because
the <tt CLASS=literal>HelloWorld</tt> class is part of the default package,
you do not need to include the package name as part of the class
name on the command line. If the <tt CLASS=literal>HelloWorld</tt>
class were part of a package called <tt CLASS=literal>student.language</tt>,
however, you would have to include the package name on the command line.
For example, you would run the application as follows:

<DIV CLASS=screen>
<P>
<PRE>
C:\&gt; java student.language.HelloWorld
</PRE>
</DIV>

<P CLASS=para>
Any additional arguments specified on the command line are
passed to the <tt CLASS=literal>main()</tt> method in its <tt CLASS=literal>String[]</tt>
parameter. For the "Hello World" application, the <tt CLASS=literal>String[]</tt>
parameter is an empty array. If, however, there were command-line arguments,
the first array element, <tt CLASS=literal>String[0]</tt>, would correspond
to the first command-line argument specified after the class name,
<tt CLASS=literal>String[1]</tt> would correspond to the next command-line
element, and so on. The name of the class does not appear as an
element in the array of parameters passed to the <tt CLASS=literal>main()</tt>
method. This is different than in C/C++, where the first element
in the array of command-line arguments identifies the program name
and the second element is the first command-line argument.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch01_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch01_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Compiling a Java Source File</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Notational Conventions</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
